import request from '@/utils/request.js'
import config from '@/utils/config/index.js'

/**
 * 获取附件信息
 */
export function getAttachment(attachmentIds) {
	const params = {
		ids: attachmentIds
	}
	return request.post({
		url: '/platform/v3/file/attachment/transfer',
		params
	});
}

/**
 * 文件重命名
 */
export function fileModifyName(params) {
	return request.post({
		url: '/platform/v3/file/attachment/modifyName',
		params
	});
}

/**
 * 下载文件
 */
export async function fileDownload(attachmentId) {
	let result = await uni.request({
		url: config.baseUrl + '/platform/v3/file/download',
		data: { attachmentId },
		method: 'GET',
		responseType: 'arraybuffer'
	})
	return result[1].data
}

/**
 * 获取文件集临时ID
 */
export function getCollectionId() {
	return request.get({
		url: "/extend/v3/DocumentCollection/getCollectionId",
		loading: false
	})
}

/**
 * 保存业务信息
 */
export function saveBusinessRelaInfo(params) {
	return request.get({
		url: "/extend/v3/DocumentCollection/saveBusinessRelaInfo",
		params,
		loading: false
	})
}

/**
 * 获取文件
 */
export function getFileByCollId(collectionId) {
	return request.get({
		url: "/extend/v3/DocumentCollection/getFileByCollId",
		params: { collectionId },
		loading: false
	})
}

/**
 * 删除文件
 */
export function deleteCollByFileId(params) {
	return request.get({
		url: "/extend/v3/DocumentCollection/deleteCollByFileId",
		params,
		loading: false
	})
}

/**
 * 重命名文件
 */
export function updateFileName(params) {
	return request.get({
		url: "/extend/v3/DocumentCollection/updateFileName",
		params,
		loading: false
	})
}

/**
 * 查询文件目录树信息
 */
export function getDocDirTreeData(params) {
	return request.post({
		url: '/extend/v3/cpisDocumentDir/findTreeData',
		params,
		paramType: 'post'
	});
}

/**
 * 查询文件目录树信息
 */
export function getDocDirTreeDataAll(filterText) {
	return request.get({
		url: "/extend/v3/cpisDocumentDir/findTreeDataAll",
		params: { filterText },
		loading: false
	})
}

/**
 * 文件归档
 */
export function saveDocDirFile(params) {
	return request.post({
		url: '/extend/v3/cpisDocumentDirFile/save',
		params,
		paramType: 'post'
	});
}